package cn.hexcloud.dga.governance.assessor.security;

import cn.hexcloud.dga.common.constant.MetaConst;
import cn.hexcloud.dga.governance.assessor.Assessor;
import cn.hexcloud.dga.governance.bean.AssessParam;
import cn.hexcloud.dga.governance.bean.GovernanceAssessDetail;
import cn.hexcloud.dga.meta.bean.TableMetaInfo;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component("SECURITY_LEVEL")
public class SecurityLevelAssessor extends Assessor {
    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {
        TableMetaInfo tableMetaInfo = assessParam.getTableMetaInfo();
        String securityLevel = tableMetaInfo.getTableMetaInfoExtra().getSecurityLevel();
        if(securityLevel.equals(MetaConst.SECURITY_LEVEL_UNSET)){
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("未设置安全等级");
            String governanceUrl = assessParam.getGovernanceMetric().getGovernanceUrl().replace("{tableId}", tableMetaInfo.getId() + "");
            governanceAssessDetail.setGovernanceUrl(governanceUrl);
        }
    }
}
